﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using KP_CommonLibrary.KP_CommonControls.NumericInput;
using System.Drawing.Design;

namespace KP_CommonLibrary.KP_CommonControls.NumericInput
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class MaskData
    {
        // Fields
        private bool beepOnError;
        private string blank;
        private string editMask;
        private bool enableEvent;
        private bool ignore;
        private MaskType maskType;
        private bool saveLiteral;

        // Events
        public event ChangeEventHandler AfterChange;

        // Methods
        public MaskData()
        {
            this.saveLiteral = true;
            this.blank = "_";
            this.editMask = string.Empty;
            this.ignore = true;
            this.enableEvent = true;
        }

        public MaskData(MaskData data)
        {
            this.saveLiteral = true;
            this.blank = "_";
            this.editMask = string.Empty;
            this.ignore = true;
            this.enableEvent = true;
            this.Assign(data);
        }

        public void Assign(MaskData data)
        {
            if (this.editMask != data.editMask)
            {
                this.enableEvent = false;
            }
            this.IgnoreMaskBlank = data.ignore;
            this.BeepOnError = data.beepOnError;
            this.SaveLiteral = data.saveLiteral;
            this.Blank = data.blank;
            this.MaskType = data.maskType;
            this.enableEvent = true;
            this.EditMask = data.editMask;
        }

        public bool Compare(MaskData sample)
        {
            foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this))
            {
                object obj2 = descriptor.GetValue(sample);
                object obj3 = descriptor.GetValue(this);
                if (!obj2.Equals(obj3))
                {
                    return false;
                }
            }
            return true;
        }

        internal void DoAfterChange(string name, object value)
        {
            if (this.enableEvent && (this.AfterChange != null))
            {
                ChangeEventArgs e = new ChangeEventArgs(name, value);
                this.AfterChange(this, e);
            }
        }

        // Properties
        [Localizable(true), Description("Obsolete. Gets or sets a value determining whether to produce a warning sound when an error occurs."), DefaultValue(false), Category("Mask")]
        public bool BeepOnError
        {
            get
            {
                return this.beepOnError;
            }
            set
            {
                this.beepOnError = value;
            }
        }

        [Localizable(true), Description("Obsolete. Gets or sets a value representing blank areas within a masked editor."), Category("Mask"), DefaultValue("_")]
        public string Blank
        {
            get
            {
                if (this.blank.Length <= 0)
                {
                    return "_";
                }
                return this.blank.Substring(0, 1);
            }
            set
            {
                string str = (value.Length == 0) ? " " : value;
                if (this.blank != str)
                {
                    this.blank = str;
                    this.DoAfterChange("Blank", this.blank);
                }
            }
        }

        [Localizable(true), Description("Obsolete. Gets or sets a value representing a mask expression."), Editor("DevExpress.XtraEditors.Design.MaskEditor, DevExpress.XtraEditors.v9.2.Design", typeof(UITypeEditor)), Category("Mask"), DefaultValue("")]
        public string EditMask
        {
            get
            {
                return this.editMask;
            }
            set
            {
                if (!this.editMask.Equals(value))
                {
                    this.editMask = value;
                    this.DoAfterChange("EditMask", value);
                }
            }
        }

        [Description("Obsolete. Gets or sets a value determining whether to ignore skipped positions within a mask editor."), Localizable(true), DefaultValue(true), Category("Mask")]
        public bool IgnoreMaskBlank
        {
            get
            {
                return this.ignore;
            }
            set
            {
                this.ignore = value;
            }
        }

        [DefaultValue(0), Description("Obsolete. Gets or sets a value specifying which mask type is used."), Localizable(true), Category("Mask")]
        public MaskType MaskType
        {
            get
            {
                return this.maskType;
            }
            set
            {
                if (this.maskType != value)
                {
                    this.maskType = value;
                    this.DoAfterChange("MaskType", value);
                }
            }
        }

        [Localizable(true), Description("Obsolete. Gets or sets a value determining whether to include literal characters in the BaseEdit.EditValue property of the mask editor."), Category("Mask"), DefaultValue(true)]
        public bool SaveLiteral
        {
            get
            {
                return this.saveLiteral;
            }
            set
            {
                if (this.saveLiteral != value)
                {
                    this.saveLiteral = value;
                    this.DoAfterChange("SaveLiteral", value);
                }
            }
        }
    }


}
